<template>
  <a-modal
    :title="currTitle"
    :visible="visible"
    :closable="false"
    centered
    :confirm-loading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel" 
    width="900px"
    :key="outKey"
  >
  <div style="width:100%;height:550px;">
    <transfer-check v-if="visible" ref="transferSelect" :url="url" :tab-columns="tabColumns" :origin-target-keys="originTargetKeys" :key-name="keyName" :projectBuildId="projectBuildId"/>
  </div>
  </a-modal>
</template>
<script>
export default {
  components: {
    TransferCheck: () => import('@/components/tools/TransferCheck'),
  },
  name: 'ProductSelect',
  props:{
    title:{
      type:String,
      default:"选择成品",
      required:false
    },
    limit:{
      type:Number,
      default:0,
      required:false
    },
    outKey:{
      type:String,
      default:'',
      required:false
    },
    outUrl:{
      type:String,
      default:"",
      required:false
    },
    outColumns:{
      type:Array,
      default: () => {
        return []
      },
      required:false
    },
    originTargetKeys:{
      type:Array,
      default: () => {
        return []
      }
    },
     projectBuildId:{
      type:String,
      default:"",
      required:false
    }
  },
  data() {
    return {
      visible:false,
      currTitle:this.title,
      confirmLoading: false,
      keyName:'productId',
      url:'/projectAcceptanceProduct/queryProduct',
      tabColumns:[
        {
          width:"110px",
          dataIndex: 'productId',
          title: '产品编号',
        },
        {
          width:"200px",
          dataIndex: 'productName',
          title: '产品名称',
        },
      ],
    };
  },
  mounted() {
   if (this.outUrl&&this.outUrl!=''){
      this.url = this.outUrl;
      this.tabColumns = this.outColumns;
      this.keyName = this.outKey;
    }
  },
  methods: {
    doSelect(){
      this.visible=true;
    },
    handleOk(){
      let result = this.$refs.transferSelect.targetRows;
      if(result.length===0){
        this.$message.warning('请先选择产品');
        return;
      }
      if(this.limit>0&&result.length>this.limit){
        this.$message.warning('最多只能选择'+this.limit+'个产品');
        return;
      }
      this.$emit('setResult',result);
      this.visible=false;
    },
    handleCancel(){
      this.visible=false;
    }
  },
};
</script>
<style lang="less" scoped>
/deep/ .ant-transfer-list .ant-btn-primary{
  color: #bbb;
}
/deep/ .ant-transfer-list:first-of-type .ant-transfer-list-header-selected{
  display: none;
}
/deep/ .ant-modal-content{
  border-radius: 15px;
}
/deep/ .ant-modal-title,/deep/ .ant-modal-footer{
  text-align: center;
}
/deep/ .ant-transfer-operation .ant-btn-primary{
  background-color: #f5f5f5 !important;
}
/deep/ .ant-modal-header{
  border-radius: 15px 15px 0 0;
  background-image: linear-gradient(90deg, #15b1ff 0%,#1158c9 100%);
}
/deep/ .ant-modal-title{
  color: #fff;
}
</style>